<?php
/**
Primary Author: Alex Arey
Updated: 3/28/2012

Handles DBTable for announcments that show on index page. Only query and update by type is supported;
announcements for new user types must be bootstrapped in the database directly.

*/
class Application_Model_DbTable_Announcements extends Zend_Db_Table_Abstract {
	
protected $_name = 'ANNOUNCEMENTS';

/**
 * Updates the announcement stored for the given user type.
 * @param varchar2 $type - user type for the announcement.
 * @param varchar2 $content - content of announcement.
 * @throws UnexpectedValueException if type not in ('STUDENT', 'FACULTY', 'PARTNER', 'ADMIN', 'NOLOGIN')
 */
public function updateAnnouncement($type, $content){
	if(!$this->isValidType($type)){
		throw new UnexpectedValueException($type.' is not a valid user type');
	}
	$data = array(
		'CONTENT'=> $content,
		);
	$this->update($data, 'TYPE = \''.$type.'\'');
}

public function getAnnouncement($type){
	if(!$this->isValidType($type)){
		throw new UnexpectedValueException($type.' is not a valid user type');
	}
	$data = $this->fetchRow('TYPE = \''.$type.'\'')->toArray();
	return $data['CONTENT'];
}

private function isValidType($type){
	return $type=='STUDENT' || $type=='FACULTY' ||
		$type=='PARTNER'||$type=='ADMIN'|| $type=='NOLOGIN';
}

/*
ID - NUMBER, PK, NOT NULL
TYPE - VARCHAR2, 20, NOT NULL
CONTENT - VARCHAR2, 1024
*/

}